<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
if (!defined("WagerResult_lib_include")){
	define("WagerResult_lib_include", 1);
	include_once(__Modules_Path."/Lotto.lib.php");

/**
 * 將注單由 bet_BetListTmp 轉到 bet_BetList
 * @param	intGID：操盤序號
 * @return	 true -> 成功，false -> 失敗
 */
	function MoveWagerList($intGID){
		global $_ConnMaster;
		$intGID = intval($intGID);

		if($intGID < 0){
			$GLOBALS["errormessage"] = "Find Wager Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".$intGID."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;			
		}

		$strSQL = "select * from `bet_BetListTmp` where GambleID = ".$intGID;
		if(!$RS = @PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Find Wager Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		if(PMA_mysql_num_rows($RS) == 0)return true;

		while($Rows = PMA_mysql_fetch_array($RS, MYSQL_ASSOC)){
			$arrFName = array();
			while(list($k, $v) = each($Rows)){
				$arrFName[] = (is_int($v))?$v:"'".$v."'";
			}
			$arrValue[] = "(".join(",", $arrFName).")";
		}
		@mysql_free_result($RS);

		$strSQL = "delete from `bet_BetList` where GambleID = ".$intGID;
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Delete Wager Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		$strSQL = "INSERT INTO `bet_BetList` VALUES ".join(",", $arrValue);
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Move Wager Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		return true;
	}


/**
 * 計算注單結果
 * @param	arrLID：樂透參數陣列
 * @param	intGID：操盤序號
 * @return	 true -> 成功，false -> 失敗
 */
	function CalculateWager($arrLotto, $intGID){
		global $_ConnMaster;
		if(!makeShowScoreFile($arrLotto["ID"], "", "", "{OnCount}"))return false;
		if(!$objScore = getLottoScore($intGID))return false;

		switch($arrLotto["LType"]){
			case 2:
				/*if($arrLotto["ID"] == 7 || $arrLotto["ID"] == 8){
					$arrScore = explode(",", $objScore -> NumberNormal);
					if(sizeof($arrScore) == 5)$objScore -> NumberNormal = $arrScore[2].",".$arrScore[3].",".$arrScore[4];
				}*/
				return Calculate3DWager($arrLotto, $intGID, $objScore);
				break;

			case 3:
				return Calculate7StarWager($arrLotto, $intGID, $objScore);
				break;

			case 4:
				return Calculate10MinWager($arrLotto, $intGID, $objScore);
				break;
		}

		$arrDeadRateType = array(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
		$arrNorm = explode(",", $objScore -> NumberNormal);
		for($i = 0; $i < sizeof($arrNorm); $i++){
			$intNormSum += intval($arrNorm[$i]);
		}

		$flWinRate = 1;
		for($intBT = 1; $intBT <= 29; $intBT++){
			if($intBT >=7 && $intBT <= 11 || $intBT == 15)continue;
			$arrC = getCalculateCondition($arrLotto, $intBT, $objScore -> NumberSpecial, $objScore -> NumberNormal, $intNormSum);

			$strSQL = "update `bet_BetList` use index (GambleID) set  ".
					"MemResult = if(".$arrC["WinTerms"].", MemPayOff*".$arrC["flWinRate"].", -1*MemStake*".$arrC["flWinRate"]."), ".
					"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$arrDeadRateType[$intBT].",1)*".$arrC["flWinRate"]."), ".
					"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$arrDeadRateType[$intBT].",1)*".$arrC["flWinRate"]."), ".
					"SubRateResult = SubResult*SubRate, ".
					"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$arrDeadRateType[$intBT].",1)*".$arrC["flWinRate"]."*1000)/1000,".
					"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$arrDeadRateType[$intBT].",1)*".$arrC["flWinRate"]."*1000)/1000,".
					"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$arrDeadRateType[$intBT].",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$arrDeadRateType[$intBT].",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$arrDeadRateType[$intBT].",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$arrDeadRateType[$intBT].",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*StockRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$arrDeadRateType[$intBT].",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$arrDeadRateType[$intBT].",1)*".$arrC["flWinRate"]."*1000)/1000 ".
					"where GambleID = ".$intGID." ".
					"and isPayOff >=0 ".
					"and Bet_Type = ".$intBT;
			//$T = time();
			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Calculate Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
			//print $strSQL."\n";
			//print (time() - $T)."\n"."\n";
			if($arrC["DrawTerms"] != ""){
				$strSQL = "update `bet_BetList` use index (GambleID) set MemResult = 0, SubIncome = 0,  SubResult = 0, SubRateResult = 0, ".
						"MainResult = 0, MainRateResult = 0, StockResult = 0, StockRateResult = 0, DirectorResult = 0,  DirectorRateResult = 0 ".
						"where  GambleID = ".$intGID." and isPayOff >=0 and Bet_Type = ".$intBT." and ".$arrC["DrawTerms"];
				//$T = time();
				if(!PMA_mysql_query($strSQL, $_ConnMaster)){
					$GLOBALS["errormessage"] = "Calculate Wager Error!!";
					$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
					return false;
				}
				//print $strSQL."\n";
				//print (time() - $T)."\n"."\n";
			}
		}  // for($intBT = 1; $intBT <= 29; $intBT++)
		//計算連碼
		if(!getJoinNumberCalculate($arrLotto, $intGID, $objScore -> NumberSpecial, $objScore -> NumberNormal))return false;
		//計算過關
		if(!getParlaysNumberCalculate($arrLotto, $intGID, $objScore -> NumberSpecial, $objScore -> NumberNormal))return false;
		//計算六肖
		if(!getSixAnimalsCalculate($arrLotto, $intGID, $objScore -> NumberSpecial))return false;
		//計算 五不中 生肖連 尾數連
		if(!getNewBTFAMCalculate($arrLotto, $intGID, $objScore -> NumberSpecial, $objScore -> NumberNormal))return false;

		$strSQL = "update `bet_BetList`  use index (GambleID) ".
						"set MemResult = 0, SubIncome = 0,  SubResult = 0, SubRateResult = 0, MainResult = 0, MainRateResult = 0, StockResult = 0,  StockRateResult = 0, DirectorResult = 0,  DirectorRateResult = 0 ".
						"where  GambleID = ".$intGID." and isPayOff < 0 ";

		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		if(!makeShowScoreFile($arrLotto["ID"], "", "", ""))return false;
		return true;
	}



/**
 * 取得各下注方式計算條件
 * @param	arrLotto 樂透參數陣列
 * @param	intBT 下注種類序號
 * @param	intNumSp 特碼號碼
 * @param	strNumN 正碼號碼字串
 * @param	intNSum 正碼總和
 * @return	 Array
 */
	function getCalculateCondition($arrLotto, $intBT, $intNumSp, $strNumN, $intNSum){
		$flWinRate = 1;
		switch($intBT){
			case 1:
			case 28: //特碼46
				 $WinTerms = "Number = ".(string)$intNumSp;
				break;
			//特碼單雙
			case 2;
				if($intNumSp == (int)$arrLotto["DrawSpecial"]){
					$flWinRate = 0;
					$WinTerms = "Number = 0";
				}elseif($intNumSp % 2 == 0){
					$WinTerms = "Number = 1";
				}else{
					$WinTerms = "Number = 0";
				}
				break;
			//特碼大小
			case 3:
				if($intNumSp == (int)$arrLotto["DrawSpecial"]){	//和局
					$flWinRate = 0;
					$WinTerms = "Number = 0";
				}elseif($intNumSp >= (int)$arrLotto["SpecialOverNumber"]){	//大
					$WinTerms = "Number = 0";
				}else{	//小
					$WinTerms = "Number = 1";
				}
				break;
			//正碼
			case 4:
				$WinTerms = "Number in (".$strNumN.")";
				break;
			//總和單雙
			case 5:
				$intNSum += $intNumSp;
				if($intNSum % 2 == 0){	 //雙
					$WinTerms = "Number = 1";
				}else{	//單
					$WinTerms = "Number = 0";
				}
				break;
			//總和大小
			case 6:
				$intNSum += $intNumSp;
				if($intNSum >= (int)$arrLotto["NormalOverNumber"]){	 //大
					$WinTerms = "Number = 0";
				}else{	//小
					$WinTerms = "Number = 1";
				}
				break;
			//正碼 1-6 單雙
			case 12:
				$arrWin = array();
				$arrOther = array();
				$arrNumN = explode(",", $strNumN);
				foreach($arrNumN as $i => $j){
					if((int)$j == (int)$arrLotto["DrawSpecial"]){	 //和局
						$arrOther[] = (string)(($i+1)*10).",".(string)(($i + 1)*10 + 1);
					}elseif((int)$j % 2 == 0){	//雙
						$arrWin[] = (string)(($i+1)*10 + 1);
					}else{	//單
						$arrWin[] = (string)(($i+1)*10);
					}
				}
				$WinTerms = "Number in (".join(",", $arrWin).")";
				if(sizeof($arrOther) > 0)$DrawTerms = "Number in (".join(",", $arrOther).")";
				break;
			//正碼 1-6 大小
			case 13:
				$arrWin = array();
				$arrOther = array();
				$arrNumN = explode(",", $strNumN);
				foreach($arrNumN as $i => $j){
					if((int)$j == (int)$arrLotto["DrawSpecial"]){	 //和局
						$arrOther[] = (string)(($i+1)*10).",".(string)(($i + 1)*10 + 1);
					}elseif((int)$j >= (int)$arrLotto["SpecialOverNumber"]){	//大
						$arrWin[] = (string)(($i+1)*10);
					}else{	//小
						$arrWin[] = (string)(($i+1)*10 + 1);
					}
				}
				$WinTerms = "Number in (".join(",", $arrWin).")";
				if(sizeof($arrOther) > 0)$DrawTerms = "Number in (".join(",", $arrOther).")";
				break;
			//正碼 1-6 色波
			case 14:
				$arrWin = array();
				$arrNumN = explode(",", $strNumN);
				$arrColorSet = explode(",", $arrLotto["ColorSet"]);
				foreach($arrNumN as $i => $j){
					foreach($arrColorSet as $k => $v){
						if(($k + 1) == (int)$j)$arrWin[$i] = (string)(($i + 1)*10 + (int)$v);
					}
				}
				$WinTerms = "Number in (".join(",", $arrWin).")";
				break;
			//正碼 1-6 合數單雙
			case 27:
				$arrWin = array();
				$arrOther = array();
				$arrNumN = explode(",", $strNumN);
				foreach($arrNumN as $i => $j){
					if((int)$j == (int)$arrLotto["DrawSpecial"]){	 //和局
						$arrOther[] = (string)(($i+1)*10).",".(string)(($i + 1)*10 + 1);
					}else{
						if((floor((int)$j / 10) + ((int)$j % 10)) % 2 == 0){	//合雙
							$arrWin[] = (string)(($i+1)*10 + 1);
						}else{	//合單
							$arrWin[] = (string)(($i+1)*10);
						}
					}
				}
				$WinTerms = "Number in (".join(",", $arrWin).")";
				//print $WinTerms;
				if(sizeof($arrOther) > 0)$DrawTerms = "Number in (".join(",", $arrOther).")";
				break;
			//特碼合數單雙
			case 16:
				$intTmp = ($intNumSp % 10)+floor($intNumSp / 10);
				if($intNumSp == (int)$arrLotto["DrawSpecial"]){
					$flWinRate = 0;
					$WinTerms = "Number = 0";
				}elseif($intTmp % 2 == 0){
					$WinTerms = "Number = 1";
				}else{
					$WinTerms = "Number = 0";
				}
				break;
			//特碼色波
			case 17:
				$arrColorSet = explode(",", $arrLotto["ColorSet"]);
				foreach($arrColorSet as $k => $v){
					if(($k + 1) == $intNumSp)$WinTerms = "Number = ".$v;
				}
				break;
			//特碼生肖
			case 18:
				$arrAnimals = getAnimalsParams($arrLotto["ID"]);
				foreach($arrAnimals as $k => $v){
					if(strpos($v, sprintf("%02s", $intNumSp)) !== false)$WinTerms = "Number = ".(string)$k;
				}
				break;
			//一般生肖
			case 19:
				$arrNum = explode(",", $strNumN);
				$arrNum[] = $intNumSp;
				$arrAnimals = getAnimalsParams($arrLotto["ID"]);
				foreach($arrAnimals as $k => $v){
					foreach($arrNum as $intN){
						if(strpos($v, sprintf("%02s", $intN)) !== false)$arrN[$k] = $k;
					}
				}
				$WinTerms = "Number in (".join(",", $arrN).")";
				break;
			//一般尾數
			case 20:
				$arrNum = explode(",", $strNumN);
				$arrNum[] = $intNumSp;
				foreach($arrNum as $intN){
					$intMantissa = $intN % 10;
					$arrN[$intMantissa] = $intMantissa;
				}
				$WinTerms = "Number in (".join(",", $arrN).")";
				break;
			//正1-6特
			case 21:
			case 22:
			case 23:
			case 24:
			case 25:
			case 26:
				$arrNum = explode(",", $strNumN);
				$WinTerms = "Number in (".$arrNum[$intBT - 21].")";
				break;
			//特半波
			case 29:
				$arrColorSet = explode(",", $arrLotto["ColorSet"]);
				if($intNumSp == (int)$arrLotto["DrawSpecial"]){	//和局
					$flWinRate = 0;
					$WinTerms = "Number = 0";
				}else{
					foreach($arrColorSet as $k => $v){
						if(($k + 1) == $intNumSp){
							$intN1 = (($k + 1) % 2 == 1)?($v*4):($v*4+1);
							$intN2 = (($k + 1) >= (int)$arrLotto["SpecialOverNumber"])?($v*4+2):($v*4+3);
						}
					}
					$WinTerms = "Number in (".$intN1.",".$intN2.")";
				}
				break;
		}  // switch($i)
		$arrC["WinTerms"] = $WinTerms;
		$arrC["DrawTerms"] = $DrawTerms;
		$arrC["flWinRate"] = $flWinRate;
		return $arrC;
	}

/**
 * 計算過關
 * @param	arrLotto：樂透參數陣列
 * @param	intGID：操盤序號
 * @param	intNumSp：特碼號碼
 * @param	strNumN：正碼號碼字串
 * @return	 boolin
 */
	function getParlaysNumberCalculate($arrLotto, $intGID, $intNumSp, $strNumN){
		global $_ConnMaster;
		$arrBT = array(1 => 15, 4 => 14);
		$arrBTRange = array(1 => array(12, 14), 4 => array(11, 13));

		$intPreBT = $arrBT[$arrLotto["LType"]];
		$intMinBT = $arrBTRange[$arrLotto["LType"]][0];
		$intMaxBT = $arrBTRange[$arrLotto["LType"]][1];
		for($intBT = $intMinBT; $intBT <= $intMaxBT; $intBT++){
			if($arrLotto["LType"] == 1){
				$arrC = getCalculateCondition($arrLotto, $intBT, $intNumSp, $strNumN, 0);
			}elseif($arrLotto["LType"] == 4){
				$arrC = getCalculate10MinCondition($arrLotto, $intBT, $strNumN, $intNumSp);
			}

			if(empty($arrC["DrawTerms"]))$arrC["DrawTerms"] = "Number in (0)";
			$strSQL = "update `bet_ParlaysNumber` set  ".
				"WinRate = if(".$arrC["WinTerms"].", 1, if(".$arrC["DrawTerms"].", 0, -1)) ".
				"where GambleID = '".$intGID."' and Bet_Type = '".$intBT."'";
			//$T = time();
			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Calculate Parlays Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
			//print $strSQL."\n";
			//print (time() - $T)."\n"."\n";
		}

		//計算過關『輸』的注單
		$strSQL = "select DISTINCT BetListID from `bet_ParlaysNumber` where GambleID = '".$intGID."' and WinRate < 0 ";
		//$T = time();
		if(!$RS = PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Calculate Parlays Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";
		$arrBID_Lost = array();
		$intDeadRateType = 1;
		if(PMA_mysql_num_rows($RS) > 0){
			while($Rows = PMA_mysql_fetch_object($RS)){
				$arrBID_Lost[] = $Rows -> BetListID;
			}
			$strSQL = "update `bet_BetList` set  ".
					"MemResult = -1*MemStake, ".
					"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)*1), ".
					"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)*1), ".
					"SubRateResult = SubResult*SubRate, ".
					"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*1*1000)/1000,".
					"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000,".
					"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
					"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
					"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
					"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
					"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
					"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000 ".
					"where GambleID = ".$intGID." ".
					"and isPayOff >=0 and Bet_Type = ".$intPreBT." ".
					"and ID in (".join(",", $arrBID_Lost).")";
			//$T = time();
			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Calculate Parlays Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
			//print $strSQL."\n";
			//print (time() - $T)."\n"."\n";
		} //if(PMA_mysql_num_rows($RS) > 0)//

		//計算過關『贏』的注單
		$strSQL = "select BetListID, WinRate, Odds from `bet_ParlaysNumber` where GambleID = '".$intGID."'";
		$strSQL .= (sizeof($arrBID_Lost) > 0)?" and BetListID not in (".join(",", $arrBID_Lost).")":"";
		if(!$RS = PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Calculate Parlays Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		if(PMA_mysql_num_rows($RS) == 0)return true;
		$arrPayOdds = array();
		while($Rows = PMA_mysql_fetch_object($RS)){
			if(empty($arrPayOdds[$Rows -> BetListID]))$arrPayOdds[$Rows -> BetListID] = 1;
			$arrPayOdds[$Rows -> BetListID] *= ($Rows -> WinRate == 0)?1:$Rows -> Odds;
		}

		foreach($arrPayOdds as $intBT => $flPayOdds){
			$strSQL = "update `bet_BetList` set  ".
					"MemResult = ".(string)($flPayOdds-1)."*MemStake, ".
					"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)*1), ".
					"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)*1), ".
					"SubRateResult = SubResult*SubRate, ".
					"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*1*1000)/1000,".
					"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000,".
					"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
					"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
					"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
					"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
					"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
					"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000 ".
					"where ID = '".$intBT."' and Bet_Type = ".$intPreBT." ";
			//$T = time();
			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Calculate Parlays Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
			//print $strSQL."\n";
			//print (time() - $T)."\n"."\n";
		}
		return true;
	}

/**
 * 計算連碼
 * @param	arrLotto：樂透參數陣列
 * @param	intGID：操盤序號
 * @param	intNumSp：特碼號碼
 * @param	strNumN：正碼號碼字串
 * @return	 boolin
 */
	function getJoinNumberCalculate($arrLotto, $intGID, $intNumSp, $strNumN){
		global $_ConnMaster;
		//$T = time();
		$strNumSQL = "";
		$arrNumN = explode(",", $strNumN);
		$strSQL = "update `bet_BetList` use index (GambleID), `bet_BetListContent` set bet_BetListContent.NNWin = ";
		foreach($arrNumN as $strV){
			$strSQL .= "if(LOCATE('".sprintf("%02s", $strV)."', JoinNumber) > 0, 1, 0) + ";
			$strNumSQL .= "'".sprintf("%02s", $strV)."', ";
		}
		$strSQL .= " 0 , bet_BetListContent.NSWin = if(LOCATE('".sprintf("%02s", $intNumSp)."', JoinNumber) > 0, 1, 0) where bet_BetList.ID = bet_BetListContent.ID and bet_BetList.Bet_Type in (7, 8, 9, 10, 11) and bet_BetList.GambleID = '".$intGID."' and bet_BetList.Number = 0";
		//print $strSQL;
		//print (time() - $T)."<br>";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";

		$arrSQL = array();
		//三全中
		$arrSQL[7] = "update bet_BetList use index (GambleID), bet_BetListContent set bet_BetList.MemResult = bet_BetListContent.OneStake*SUBSTRING('00000001041020', bet_BetListContent.NNWin*2 + 1, 2)*bet_BetList.Odds - bet_BetList.MemStake";

		//三全二
		$arrSQL[8] = "update bet_BetList use index (GambleID), bet_BetListContent set bet_BetList.MemResult = bet_BetListContent.OneStake*(SUBSTRING('00000001041020', bet_BetListContent.NNWin*2 + 1, 2)*bet_BetList.Odds2 + ROUND((LENGTH(JoinNumber) + 1) / 3 - bet_BetListContent.NNWin)*SUBSTRING('00000103061015', bet_BetListContent.NNWin*2 + 1, 2)*bet_BetList.Odds) - bet_BetList.MemStake";

		//二全中
		$arrSQL[9] = "update bet_BetList use index (GambleID), bet_BetListContent set bet_BetList.MemResult = bet_BetListContent.OneStake*SUBSTRING('00000103061015', bet_BetListContent.NNWin*2 + 1, 2)*bet_BetList.Odds - bet_BetList.MemStake";

		//二中特
		$arrSQL[10] = "update bet_BetList use index (GambleID), bet_BetListContent set bet_BetList.MemResult = bet_BetListContent.OneStake*(bet_BetListContent.NNWin*bet_BetListContent.NSWin*bet_BetList.Odds + SUBSTRING('00000103061015', bet_BetListContent.NNWin*2 + 1, 2)*bet_BetList.Odds2) - bet_BetList.MemStake";

		//特串
		$arrSQL[11] = "update bet_BetList use index (GambleID), bet_BetListContent set bet_BetList.MemResult = bet_BetListContent.OneStake*bet_BetListContent.NNWin*bet_BetListContent.NSWin*bet_BetList.Odds - bet_BetList.MemStake";
		//print (time() - $T)."<br>";
		foreach($arrSQL as $key => $strSQL){
			$strSQL .= " where bet_BetList.ID = bet_BetListContent.ID and bet_BetList.Bet_Type = ".$key." and bet_BetList.GambleID = '".$intGID."'  and bet_BetList.Number = 0";
			//$T = time();
			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
			//print $strSQL."\n";
			//print (time() - $T)."\n"."\n";
		}

		/***********************************************************************************************************/
		//計算排碰
		$strSQL = "update `bet_BetList` use index (GambleID), `bet_BetListContent` ".
				  "set bet_BetList.MemResult = bet_BetListContent.OneStake*CountJNLineTouch(".$strNumSQL."'".sprintf("%02s", $intNumSp)."', JoinNumber, Bet_Type, Odds, Odds2) - bet_BetList.MemStake".
				  " where bet_BetList.ID = bet_BetListContent.ID and bet_BetList.Bet_Type in (7, 8, 9, 10, 11) and bet_BetList.GambleID = '".$intGID."' and bet_BetList.Number = 1";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		$intDeadRateType = 1;
		$strSQL = "update `bet_BetList` set  ".
				"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubRateResult = SubResult*SubRate, ".
				"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*1000)/1000,".
				"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000,".
				"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
				"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000 ".
				"where  GambleID = ".$intGID." and Bet_Type in (7,8,9,10,11) ".
				"and isPayOff >=0 ";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";
		return true;
	}


/**
 * 計算六肖
 * @param	arrLotto 樂透參數陣列
 * @param	intGID 操盤序號
 * @param	intNumSp 特碼號碼
 * @param	strNumN 正碼號碼字串
 * @return	boolin
 */
	function getSixAnimalsCalculate($arrLotto, $intGID, $intNumSp){
		global $_ConnMaster;

		$arrAnimals = getAnimalsParams($arrLotto["ID"]);
		foreach($arrAnimals as $k => $v){
			if(strpos($v, sprintf("%02s", $intNumSp)) !== false){
				$strAnimals = $k;
				break;
			}
		}


		//將注單輸贏金額歸零
		$strSQL = "update `bet_BetList` use index (GambleID) set `MemResult` = 0 where `GambleID` = ".$intGID." and `Bet_Type` = 30";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//先將中號次數歸零
		$strSQL = "update `bet_ParlaysNumberEven` set `NNWin` = 0, `NSWin` = 0 where `GambleID` = ".$intGID." and `Bet_Type` = 30";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//計算肖連連中號次數
		$strSQL = "update `bet_ParlaysNumberEven` set 
			`NNWin` = `NNWin` + IF(`Ball1` = ".$strAnimals.", 1, 0) ,
			`NNWin` = `NNWin` + IF(`Ball2` = ".$strAnimals.", 1, 0) ,
			`NNWin` = `NNWin` + IF(`Ball3` = ".$strAnimals.", 1, 0) ,
			`NNWin` = `NNWin` + IF(`Ball4` = ".$strAnimals.", 1, 0) ,
			`NNWin` = `NNWin` + IF(`Ball5` = ".$strAnimals.", 1, 0) ,
			`NNWin` = `NNWin` + IF(`Ball6` = ".$strAnimals.", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball1` = ".($strAnimals + 12).", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball2` = ".($strAnimals + 12).", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball3` = ".($strAnimals + 12).", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball4` = ".($strAnimals + 12).", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball5` = ".($strAnimals + 12).", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball6` = ".($strAnimals + 12).", 1, 0) 
			where `GambleID` = ".$intGID." and `Bet_Type` = 30";
//print $strSQL;
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Animals Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//統計生肖，尾數連贏得金額
		$arrBTNNWin = array(30 => "`NNWin` > 0");

		foreach($arrBTNNWin as $intBT => $strNNWin){
			$strSQL = "insert into `bet_BetList`(`ID`, `MemResult`) select `BetListID`, `MemStake`*`Odds1` from `bet_ParlaysNumberEven`
			where `GambleID` = ".$intGID." and `Bet_Type` = ".$intBT." and `Ball1` <= 12 and `Ball2` <= 12 and `Ball3` <= 12 and `Ball4` <= 12 and `Ball5` <= 12 and `Ball6` <= 12 and ".$strNNWin." ON DUPLICATE KEY UPDATE `MemResult` = `MemResult` + VALUES(MemResult)";

			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
		}

		//統計不中贏得金額
		$strSQL = "insert into `bet_BetList`(`ID`, `MemResult`) select `BetListID`, `MemStake`*`Odds1` from `bet_ParlaysNumberEven` 
			where `GambleID` = ".$intGID." and `Bet_Type` = 30 and `Ball1` > 12 and `Ball2` > 12 and `Ball3` > 12 and `Ball4` > 12 and `Ball5` > 12 and `Ball6` > 12 and `NNWin` = 0 and `NSWin` = 0 ON DUPLICATE KEY UPDATE `MemResult` = `MemResult` + VALUES(MemResult)";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		$intDeadRateType = 1;
		$strSQL = "update `bet_BetList` set  ".
				"MemResult = MemResult - MemStake, ".
				"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubRateResult = SubResult*SubRate, ".
				"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*1000)/1000,".
				"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000,".
				"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
				"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000 ".
				"where  GambleID = ".$intGID." and Bet_Type = 30 ".
				"and isPayOff >=0 ";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "BT30 Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";
		return true;
	}


/**
 * 新計算五不中, 肖連, 尾連
 * @param	arrLotto 樂透參數陣列
 * @param	intGID 操盤序號
 * @param	intNumSp 特碼號碼
 * @param	strNumN 正碼號碼字串
 * @return	boolin
 */
	function getNewBTFAMCalculate($arrLotto, $intGID, $intNumSp, $strNumN){
		global $_ConnMaster;

		$arrNumN = explode(",", $strNumN);
		$arrNumN[] = $intNumSp;

		$arrAnimals = getAnimalsParams($arrLotto["ID"]);
		$arrV = array();
		foreach($arrNumN as $strV){
			foreach($arrAnimals as $k => $v){
				if(strpos($v, sprintf("%02s", $strV)) !== false){
					$arrV[$k] = $k;
				}
			}
			$arrMantissa[] = (int)$strV % 10;
		}
		$strAnimals = implode(",", $arrV);
		$strMantissa = implode(",", $arrMantissa);

		//將注單輸贏金額歸零
		$strSQL = "update `bet_BetList` use index (GambleID) set `MemResult` = 0 where `GambleID` = ".$intGID." and (`Bet_Type` between 31 and 50)";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//先將中號次數歸零
		$strSQL = "update `bet_ParlaysNumberEven` set `NNWin` = 0, `NSWin` = 0 where `GambleID` = ".$intGID." and (`Bet_Type` between 31 and 50)";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//計算中號次數
		$strSQL = "update `bet_ParlaysNumberEven` set 
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball1`, ','), ',".$strNumN.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball2`, ','), ',".$strNumN.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball3`, ','), ',".$strNumN.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball4`, ','), ',".$strNumN.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball5`, ','), ',".$strNumN.",') > 0, 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball1` = ".$intNumSp.", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball2` = ".$intNumSp.", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball3` = ".$intNumSp.", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball4` = ".$intNumSp.", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball5` = ".$intNumSp.", 1, 0) 
			where `GambleID` = ".$intGID." and (`Bet_Type` in (31, 44, 45, 46, 47, 48, 49, 50))";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//計算肖連連中號次數
		$strSQL = "update `bet_ParlaysNumberEven` set 
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball1`, ','), ',".$strAnimals.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball2`, ','), ',".$strAnimals.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball3`, ','), ',".$strAnimals.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball4`, ','), ',".$strAnimals.",') > 0, 1, 0) 
			where `GambleID` = ".$intGID." and `Bet_Type` in (32, 33, 34, 35, 36, 37)";
//print $strSQL;
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Animals Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//計算尾連中號次數
		$strSQL = "update `bet_ParlaysNumberEven` set 
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball1`, ','), ',".$strMantissa.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball2`, ','), ',".$strMantissa.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball3`, ','), ',".$strMantissa.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball4`, ','), ',".$strMantissa.",') > 0, 1, 0) 
			where `GambleID` = ".$intGID." and `Bet_Type` in (38, 39, 40, 41, 42, 43)";
//print $strSQL;
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Mantissa Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//統計生肖，尾數連贏得金額
		$arrBTNNWin = array(32 => "`NNWin` = 2",
											33 => "`NNWin` = 3",
											34 => "`NNWin` = 4",
											38 => "`NNWin` = 2",
											39 => "`NNWin` = 3",
											40 => "`NNWin` = 4"
		);

		foreach($arrBTNNWin as $intBT => $strNNWin){
			$strSQL = "insert into `bet_BetList`(`ID`, `MemResult`) select `BetListID`, `MemStake`*`Odds1` from `bet_ParlaysNumberEven`
			where `GambleID` = ".$intGID." and `Bet_Type` = ".$intBT." and ".$strNNWin." ON DUPLICATE KEY UPDATE `MemResult` = `MemResult` + VALUES(MemResult)";

			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
		}

		//統計不中贏得金額
		$strSQL = "insert into `bet_BetList`(`ID`, `MemResult`) select `BetListID`, `MemStake`*`Odds1` from `bet_ParlaysNumberEven` 
			where `GambleID` = ".$intGID." and (`Bet_Type` in (31, 35, 36, 37, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50)) and `NNWin` = 0 and `NSWin` = 0 ON DUPLICATE KEY UPDATE `MemResult` = `MemResult` + VALUES(MemResult)";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		$intDeadRateType = 1;
		$strSQL = "update `bet_BetList` set  ".
				"MemResult = MemResult - MemStake, ".
				"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubRateResult = SubResult*SubRate, ".
				"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*1000)/1000,".
				"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000,".
				"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
				"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000 ".
				"where  GambleID = ".$intGID." and (Bet_Type >= 31 and Bet_Type <= 43) ".
				"and isPayOff >=0 ";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "BT31To50 Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";
		return true;
	}


/**
 * 取得樂透開彩球號
 * @param	intGID：操盤序號
 * @return	 Object -> 成功，false -> 失敗
 */
	function getLottoScore($intGID){
		global $_ConnMaster;
		$strSQL = "select NumberNormal, NumberSpecial from `bet_GambleScore` where GambleID = ".$intGID." order by ID limit 0, 1";
		if(!$RS = @PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Find Score Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		if(PMA_mysql_num_rows($RS) == 0){
			$GLOBALS["errormessage"] = "Not Find Score Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		return PMA_mysql_fetch_object($RS);
	}

/**
 * 產生樂透開彩球號檔案
 * @param	intLID：樂透種類序號
 * @return	 true -> 成功，false -> 失敗
 */
	function getGameScoreFile($intLID){
		global $_ConnMaster;
		$strSQL = "select a.NumberNormal, a.NumberSpecial, b.GameDate, b.GameTime, b.SerialNo from `bet_GambleScore` a, `bet_Gamble` b where a.GambleID = b.ID and b.LottoID = ".$intLID." order by b.GameDate desc, b.SerialNo desc limit 0, 120";
		if(!$RS = @PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Find Score Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		if(PMA_mysql_num_rows($RS) == 0){
			$GLOBALS["errormessage"] = "Not Find Score Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		$i = 0;
		while($Rows = PMA_mysql_fetch_array($RS, MYSQL_ASSOC)){
			$arrFName = array();
			while(list($k, $v) = each($Rows)){
				$arrFName[] = "\"".$k."\"=>\"".$v."\"";
			}
			$_strCon .= "$"."_arrGameScore[".$i++."]=array(".join(",", $arrFName).");\n";
		}

		$_strCon = "<"."?"."php\n".$_strCon."?".">";
		$_strFile = __FCommon_Path."/GameScore".$intLID.".inc.php";

		if(!writeFile($_strFile, $_strCon, "w"))return false;
		return true;
	}


/**
 * 產生顯示樂透開彩球號檔案
 * @param	intLID：樂透種類序號
 * @param	strNumberNormal：正碼
 * @param	strNumberSpecial：特碼
 * @param	strMessage：訊息
 * @return	 true -> 成功，false -> 失敗
 */
	function makeShowScoreFile($intLID, $strNumberNormal, $strNumberSpecial, $strMessage){
		$_strCon = '$_NumberNormal = "'.$strNumberNormal.'";'."\n";
		$_strCon .= '$_NumberSpecial = "'.$strNumberSpecial.'";'."\n";
		$_strCon .= '$_Message = "'.$strMessage.'";'."\n";
		$_strCon = "<"."?"."php\n".$_strCon."?".">";
		$_strFile = __Common_Path."/ShowScore_".$intLID.".inc.php";

		if(!writeFile($_strFile, $_strCon, "w"))return false;
		return true;
	}


/**
 * 計算 3D 注單結果
 * @param	arrLID：樂透參數陣列
 * @param	intGID：操盤序號
 * @return	true -> 成功，false -> 失敗
 */
	function Calculate3DWager($arrLotto, $intGID, $objScore){
		global $_ConnMaster;

		$intDeadRateType = 1;

		$flWinRate = 1;
		for($intBT = 51; $intBT <= 93; $intBT++){
			if($intBT > 68 && $intBT < 84)continue;
			$arrC = getCalculate3DCondition($arrLotto, $intBT, $objScore -> NumberNormal);

			$strSQL = "update `bet_BetList` use index (GambleID) set  ".
					"MemResult = if(".$arrC["WinTerms"].", MemPayOff*".$arrC["flWinRate"].", -1*MemStake*".$arrC["flWinRate"]."), ".
					"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."), ".
					"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."), ".
					"SubRateResult = SubResult*SubRate, ".
					"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000,".
					"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000,".
					"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000 ".
					"where GambleID = ".$intGID." ".
					"and isPayOff >=0 ".
					"and Bet_Type = ".$intBT;
			//$T = time();
			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Calculate Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
			//print $strSQL."\n";
			//print (time() - $T)."\n"."\n";
			if($arrC["DrawTerms"] != ""){
				$strSQL = "update `bet_BetList` use index (GambleID) set MemResult = 0, SubIncome = 0,  SubResult = 0, SubRateResult = 0, ".
						"MainResult = 0, MainRateResult = 0, StockResult = 0, StockRateResult = 0, DirectorResult = 0,  DirectorRateResult = 0 ".
						"where  GambleID = ".$intGID." and isPayOff >=0 and Bet_Type = ".$intBT." and ".$arrC["DrawTerms"];
				//$T = time();
				if(!PMA_mysql_query($strSQL, $_ConnMaster)){
					$GLOBALS["errormessage"] = "Calculate Wager Error!!";
					$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
					return false;
				}
				//print $strSQL."\n";
				//print (time() - $T)."\n"."\n";
			}
		}  // for($intBT = 51; $intBT <= 92; $intBT++)
		//計算組 3, 6 轉直
		if(!getAssembleNumberCalculate($arrLotto, $intGID, $objScore -> NumberNormal))return false;
		//計算 3x3x3 .... 
		if(!getRowNumberCalculate($arrLotto, $intGID, $objScore -> NumberNormal))return false;

		$strSQL = "update `bet_BetList`  use index (GambleID) ".
						"set MemResult = 0, SubIncome = 0,  SubResult = 0, SubRateResult = 0, MainResult = 0, MainRateResult = 0, StockResult = 0,  StockRateResult = 0, DirectorResult = 0,  DirectorRateResult = 0 ".
						"where  GambleID = ".$intGID." and isPayOff < 0 ";

		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		if(!makeShowScoreFile($arrLotto["ID"], "", "", ""))return false;
		return true;
	}


/**
 * 取得 3D 各下注方式計算條件
 * @param	arrLotto 樂透參數陣列
 * @param	intBT 下注種類序號
 * @param	strNum 號碼字串
 * @return	 Array
 */
	function getCalculate3DCondition($arrLotto, $intBT, $strNum){
		$flWinRate = 1;

		$arrNum = explode(",", $strNum);
		$intNumSum = intval($arrNum[0]) + intval($arrNum[1]) + intval($arrNum[2]);
		$intN3 = (int)$arrNum[0];	//百位
		$intN2 = (int)$arrNum[1];	//十位
		$intN1 = (int)$arrNum[2];	//個位
		switch($intBT){
			case 51:	//定膽個位
				$WinTerms = "Number = ".$intN1;
				break;

			case 54:	//定膽十位
				$WinTerms = "Number = ".$intN2;
				break;

			case 57:	//定膽百位
				$WinTerms = "Number = ".$intN3;
				break;

			case 60:	//定膽不定位
				$WinTerms = "Number in (".$intN1.", ".$intN2.", ".$intN3.")";
				break;

			case 52:	 //定膽個位單雙
				if($intN1 % 2 == 0){
					$WinTerms = "Number = 1";
				}else{
					$WinTerms = "Number = 0";
				}
				break;

			case 53:	 //定膽個位大小
				if($intN1 > 4){
					$WinTerms = "Number = 0";
				}else{
					$WinTerms = "Number = 1";
				}
				break;

			case 55:	 //定膽十位單雙
				if($intN2 % 2 == 0){
					$WinTerms = "Number = 1";
				}else{
					$WinTerms = "Number = 0";
				}
				break;

			case 56:	 //定膽十位大小
				if($intN2 > 4){
					$WinTerms = "Number = 0";
				}else{
					$WinTerms = "Number = 1";
				}
				break;

			case 58:	 //定膽百位單雙
				if($intN3 % 2 == 0){
					$WinTerms = "Number = 1";
				}else{
					$WinTerms = "Number = 0";
				}
				break;

			case 59:	 //定膽百位大小
				if($intN3 > 4){
					$WinTerms = "Number = 0";
				}else{
					$WinTerms = "Number = 1";
				}
				break;

			case 61:	 //定膽和值
				if($intNumSum <= 6){$intNumSum = 6;}
				elseif($intNumSum >= 21 && $intNumSum <= 27){$intNumSum = 21;}
				$WinTerms = "Number = ".$intNumSum;
				break;

			case 62:	 //定膽和值單雙
				if($intNumSum % 2 == 0){
					$WinTerms = "Number = 1";
				}else{
					$WinTerms = "Number = 0";
				}
				break;

			case 63:	 //定膽和值大小
				if($intNumSum > 13){
					$WinTerms = "Number = 0";
				}else{
					$WinTerms = "Number = 1";
				}
				break;

			case 64:	//雙飛定位十個
				$WinTerms = "Number = ".($intN2*10 + $intN1);
				break;

			case 65:	//雙飛定位百個
				$WinTerms = "Number = ".($intN3*10 + $intN1);
				break;

			case 66:	//雙飛定位百十
				$WinTerms = "Number = ".($intN3*10 + $intN2);
				break;

			case 67:	//雙飛不定位
				$intNum1 = ($intN1 < $intN2)?($intN1*10 + $intN2):($intN2*10 + $intN1);
				$intNum2 = ($intN1 < $intN3)?($intN1*10 + $intN3):($intN3*10 + $intN1);
				$intNum3 = ($intN3 < $intN2)?($intN3*10 + $intN2):($intN2*10 + $intN3);
				$WinTerms = "Number in (".$intNum1.", ".$intNum2.", ".$intNum3.")";
				break;

			case 68:	//組 3全包
				if($intN1 == $intN2 && $intN2 == $intN3){
					$WinTerms = "Number = -1";
				}elseif($intN1 == $intN2 || $intN2 == $intN3 || $intN1 == $intN3){
					$WinTerms = "Number = 0";
				}else{
					$WinTerms = "Number = -1";
				}
				break;

			case 84:	//定膽個位質合
				$intNum = ($intN1 == 1 || $intN1 == 2 || $intN1 == 3 || $intN1 == 5 || $intN1 == 7)?0:1;
				$WinTerms = "Number = ".$intNum;
				break;

			case 85:	//定膽十位質合
				$intNum = ($intN2 == 1 || $intN2 == 2 || $intN2 == 3 || $intN2 == 5 || $intN2 == 7)?0:1;
				$WinTerms = "Number = ".$intNum;
				break;

			case 86:	//定膽百位質合
				$intNum = ($intN3 == 1 || $intN3 == 2 || $intN3 == 3 || $intN3 == 5 || $intN3 == 7)?0:1;
				$WinTerms = "Number = ".$intNum;
				break;

			case 87:	//單雙過關
				$arrWin = array("000" => 0, "001" => 1, "011" => 2, "010" => 3, "111" => 4, "110" => 5, "100" => 6, "101" => 7);
				$strWin = ($intN3 % 2 == 1)?"0":"1";
				$strWin .= ($intN2 % 2 == 1)?"0":"1";
				$strWin .= ($intN1 % 2 == 1)?"0":"1";
				$WinTerms = "Number = ".$arrWin[$strWin];
				break;

			case 88:	//大小過關
				$arrWin = array("000" => 0, "001" => 1, "011" => 2, "010" => 3, "111" => 4, "110" => 5, "100" => 6, "101" => 7);
				$strWin = ($intN3 > 4)?"0":"1";
				$strWin .= ($intN2 > 4)?"0":"1";
				$strWin .= ($intN1 > 4)?"0":"1";
				$WinTerms = "Number = ".$arrWin[$strWin];
				break;

			case 89:	//質合過關
				$arrWin = array("000" => 0, "001" => 1, "011" => 2, "010" => 3, "111" => 4, "110" => 5, "100" => 6, "101" => 7);
				$strWin = ($intN3 == 1 || $intN3 == 2 || $intN3 == 3 || $intN3 == 5 || $intN3 == 7)?"0":"1";
				$strWin .= ($intN2 == 1 || $intN2 == 2 || $intN2 == 3 || $intN2 == 5 || $intN2 == 7)?"0":"1";
				$strWin .= ($intN1 == 1 || $intN1 == 2 || $intN1 == 3 || $intN1 == 5 || $intN1 == 7)?"0":"1";
				$WinTerms = "Number = ".$arrWin[$strWin];
				break;

			case 90:	//跨度
				sort($arrNum);
				$WinTerms = "Number = ".abs($arrNum[2] - $arrNum[0]);
				break;

			case 91:	//合值
				$WinTerms = "Number = ".(($arrNum[2] + $arrNum[1] + $arrNum[0]) % 10);
				break;

			case 92:	//三定位
				$WinTerms = "Number = ".($intN3*100+$intN2*10+$intN1*1);
				break;

			case 93:	//三字
				$arrT = array($intN1, $intN2, $intN3);
				sort($arrT);
				$arrTmp = array();
				$arrTmp[] = $arrT[0]*100+$arrT[1]*10+$arrT[2];

				$WinTerms = "Number in (".join(",", $arrTmp).")";
				break;

		}  // switch($i)
		$arrC["WinTerms"] = $WinTerms;
		$arrC["DrawTerms"] = $DrawTerms;
		$arrC["flWinRate"] = $flWinRate;
		return $arrC;
	}


/**
 * 計算 組 3 or 6 轉直 
 * @param	arrLotto 樂透參數陣列
 * @param	intGID 操盤序號
 * @param	strNum 號碼字串
 * @return	 boolin
 */
	function getAssembleNumberCalculate($arrLotto, $intGID, $strNum){
		global $_ConnMaster;
		//$T = time();
		$arrNum = explode(",", $strNum);
		$arrSameNum = array();
		if((int)$arrNum[0] == (int)$arrNum[1] || (int)$arrNum[0] == (int)$arrNum[2] || (int)$arrNum[1] == (int)$arrNum[2])$arrSameNum = $arrNum;
		if((int)$arrNum[0] == (int)$arrNum[1] && (int)$arrNum[0] == (int)$arrNum[2])$arrSameNum = array(0);

		$strSQL = "update bet_BetList use index (GambleID), bet_BetListContent set bet_BetListContent.NNWin = 0";
		$strSQL .= " where bet_BetList.ID = bet_BetListContent.ID and bet_BetList.Bet_Type in (69, 70, 71, 72, 73, 74, 75, 76, 77) and bet_BetList.GambleID = '".$intGID."'";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Assemble Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//組 3 轉直 中獎
		if(sizeof($arrSameNum) > 0){
			$strSQL = "update bet_BetList use index (GambleID), bet_BetListContent set bet_BetListContent.NNWin = ";
			foreach($arrSameNum as $strV){
				$strSQL .= "if(LOCATE('".$strV."', JoinNumber) > 0, 1, 0) + ";
			}
			$strSQL .= " 0 where bet_BetList.ID = bet_BetListContent.ID and bet_BetList.Bet_Type in (69, 70, 71, 72) and bet_BetList.GambleID = '".$intGID."'";

		//組 6 轉直 中獎
		}else{
			$strSQL = "update bet_BetList use index (GambleID), bet_BetListContent set bet_BetListContent.NNWin = ";
			for($i = 0; $i <= 2; $i++){
				$strSQL .= "if(LOCATE('".$arrNum[$i]."', JoinNumber) > 0, 1, 0) + ";
			}
			$strSQL .= " 0 where bet_BetList.ID = bet_BetListContent.ID and bet_BetList.Bet_Type in (73, 74, 75, 76, 77) and bet_BetList.GambleID = '".$intGID."'";
		}

		//print $strSQL;
		//print (time() - $T)."<br>";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Assemble Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";


		$strSQL = "update bet_BetList use index (GambleID), bet_BetListContent set bet_BetList.MemResult = if(bet_BetListContent.NNWin >= 3, bet_BetList.MemPayOff, -1*MemStake)";

		$strSQL .= " where bet_BetList.ID = bet_BetListContent.ID and bet_BetList.Bet_Type in (69, 70, 71, 72, 73, 74, 75, 76, 77) and bet_BetList.GambleID = '".$intGID."'";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Assemble Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		$intDeadRateType = 1;
		$strSQL = "update `bet_BetList` set  ".
				"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubRateResult = SubResult*SubRate, ".
				"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*1000)/1000,".
				"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000,".
				"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
				"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000 ".
				"where  GambleID = ".$intGID." and Bet_Type in (69, 70, 71, 72, 73, 74, 75, 76, 77) ".
				"and isPayOff >=0 ";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Assemble Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";
		return true;
	}


/**
 * 計算 排碰
 * @param	arrLotto 樂透參數陣列
 * @param	intGID 操盤序號
 * @param	strNum 號碼字串
 * @return	 boolin
 */
	function getRowNumberCalculate($arrLotto, $intGID, $strNum){
		global $_ConnMaster;
		//$T = time();
		$arrNum = explode(",", $strNum);
		$arrSign = array("c", "b", "a");

		$strSQL = "update bet_BetList use index (GambleID), bet_BetListContent set bet_BetListContent.NNWin = ";
		foreach($arrNum as $key => $strV){
			$strSQL .= "if(LOCATE('".$arrSign[$key].$strV."', JoinNumber) > 0, 1, 0) + ";
		}
		$strSQL .= " 0 where bet_BetList.ID = bet_BetListContent.ID and bet_BetList.Bet_Type in (78, 79, 80, 81, 82, 83) and bet_BetList.GambleID = '".$intGID."'";

		//print $strSQL;
		//print (time() - $T)."<br>";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Row Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";


		$strSQL = "update bet_BetList use index (GambleID), bet_BetListContent set bet_BetList.MemResult = if(bet_BetListContent.NNWin = 3, bet_BetList.MemPayOff, -1*MemStake)";

		$strSQL .= " where bet_BetList.ID = bet_BetListContent.ID and bet_BetList.Bet_Type in (78, 79, 80, 81, 82, 83) and bet_BetList.GambleID = '".$intGID."'";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Row Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		$intDeadRateType = 1;
		$strSQL = "update `bet_BetList` set  ".
				"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubRateResult = SubResult*SubRate, ".
				"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*1000)/1000,".
				"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000,".
				"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
				"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000 ".
				"where  GambleID = ".$intGID." and Bet_Type in (78, 79, 80, 81, 82, 83) ".
				"and isPayOff >=0 ";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Row Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";
		return true;
	}



/**
 * 計算 7Star 注單結果
 * @param	arrLID：樂透參數陣列
 * @param	intGID：操盤序號
 * @return	true -> 成功，false -> 失敗
 */
	function Calculate7StarWager($arrLotto, $intGID, $objScore){
		global $_ConnMaster;

		$intDeadRateType = 1;

		$flWinRate = 1;
		for($intBT = 1; $intBT <= 22; $intBT++){
			$arrC = getCalculate7StarCondition($arrLotto, $intBT, $objScore -> NumberNormal);

			$strSQL = "update `bet_BetList` use index (GambleID) set  ".
					"MemResult = if(".$arrC["WinTerms"].", MemPayOff*".$arrC["flWinRate"].", -1*MemStake*".$arrC["flWinRate"]."), ".
					"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."), ".
					"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."), ".
					"SubRateResult = SubResult*SubRate, ".
					"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000,".
					"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000,".
					"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000 ".
					"where GambleID = ".$intGID." ".
					"and isPayOff >=0 ".
					"and Bet_Type = ".$intBT;

			//$T = time();
			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Calculate Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
			//print $strSQL."\n";
			//print (time() - $T)."\n"."\n";
			if($arrC["DrawTerms"] != ""){
				$strSQL = "update `bet_BetList` use index (GambleID) set MemResult = 0, SubIncome = 0,  SubResult = 0, SubRateResult = 0, ".
						"MainResult = 0, MainRateResult = 0, StockResult = 0, StockRateResult = 0, DirectorResult = 0,  DirectorRateResult = 0 ".
						"where  GambleID = ".$intGID." and isPayOff >=0 and Bet_Type = ".$intBT." and ".$arrC["DrawTerms"];
				//$T = time();
				if(!PMA_mysql_query($strSQL, $_ConnMaster)){
					$GLOBALS["errormessage"] = "Calculate Wager Error!!";
					$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
					return false;
				}
				//print $strSQL."\n";
				//print (time() - $T)."\n"."\n";
			}
		}  // for($intBT = 1; $intBT <= 22; $intBT++)

		$strSQL = "update `bet_BetList`  use index (GambleID) ".
						"set MemResult = 0, SubIncome = 0,  SubResult = 0, SubRateResult = 0, MainResult = 0, MainRateResult = 0, StockResult = 0,  StockRateResult = 0, DirectorResult = 0,  DirectorRateResult = 0 ".
						"where  GambleID = ".$intGID." and isPayOff < 0 ";

		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		if(!makeShowScoreFile($arrLotto["ID"], "", "", ""))return false;
		return true;
	}


/**
 * 取得 7Star 各下注方式計算條件
 * @param	arrLotto 樂透參數陣列
 * @param	intBT 下注種類序號
 * @param	strNum 號碼字串
 * @return	 Array
 */
	function getCalculate7StarCondition($arrLotto, $intBT, $strNum){
		$flWinRate = 1;

		$arrNum = explode(",", $strNum);
		$intN1 = (int)$arrNum[0];	//千位
		$intN2 = (int)$arrNum[1];	//百位
		$intN3 = (int)$arrNum[2];	//十位
		$intN4 = (int)$arrNum[3];	//個位
		switch($intBT){
			case 1:		//二定位 - 千百
				$WinTerms = "Number = ".($intN1*10 + $intN2);
				break;

			case 2:		//二定位 - 千十
				$WinTerms = "Number = ".($intN1*10 + $intN3);
				break;

			case 3:		//二定位 - 千個
				$WinTerms = "Number = ".($intN1*10 + $intN4);
				break;

			case 4:		//二定位 - 百十
				$WinTerms = "Number = ".($intN2*10 + $intN3);
				break;

			case 5:		//二定位 - 百個
				$WinTerms = "Number = ".($intN2*10 + $intN4);
				break;

			case 6:		//二定位 - 十個
				$WinTerms = "Number = ".($intN3*10 + $intN4);
				break;

			case 7:		//三定位 - 口口口X
				$WinTerms = "Number = ".($intN1*100 + $intN2*10 + $intN3);
				break;

			case 8:		//三定位 - 口口X口
				$WinTerms = "Number = ".($intN1*100 + $intN2*10+$intN4);
				break;

			case 9:		//三定位 - 口X口口
				$WinTerms = "Number = ".($intN1*100 + $intN3*10 + $intN4);
				break;

			case 10:	//三定位 - X口口口
				$WinTerms = "Number = ".($intN2*100 + $intN3*10 + $intN4);
				break;

			case 11:	//四定位
				$WinTerms = "Number = ".($intN1*1000 + $intN2*100 + $intN3*10 + $intN4);
				break;

			case 12:	//二字
				$arrTmp = array();
				$arrTmp[] = ($intN1 < $intN2)?($intN1*10 + $intN2):($intN2*10 + $intN1);
				$arrTmp[] = ($intN1 < $intN3)?($intN1*10 + $intN3):($intN3*10 + $intN1);
				$arrTmp[] = ($intN1 < $intN4)?($intN1*10 + $intN4):($intN4*10 + $intN1);
				$arrTmp[] = ($intN2 < $intN3)?($intN2*10 + $intN3):($intN3*10 + $intN2);
				$arrTmp[] = ($intN2 < $intN4)?($intN2*10 + $intN4):($intN4*10 + $intN2);
				$arrTmp[] = ($intN3 < $intN4)?($intN3*10 + $intN4):($intN4*10 + $intN3);

				$WinTerms = "Number in (".join(",", $arrTmp).")";
				break;

			case 13:	//三字
				$arrT = array($intN1, $intN2, $intN3, $intN4);
				sort($arrT);
				$arrTmp = array();
				$arrTmp[] = $arrT[0]*100+$arrT[1]*10+$arrT[2];
				$arrTmp[] = $arrT[0]*100+$arrT[1]*10+$arrT[3];
				$arrTmp[] = $arrT[0]*100+$arrT[2]*10+$arrT[3];
				$arrTmp[] = $arrT[1]*100+$arrT[2]*10+$arrT[3];

				$WinTerms = "Number in (".join(",", $arrTmp).")";
				break;

			case 14:	//單雙
				$arrTmp = array();
				$arrTmp[] = ($intN1 % 2 == 0)?1:0;
				$arrTmp[] = ($intN2 % 2 == 0)?11:10;
				$arrTmp[] = ($intN3 % 2 == 0)?21:20;
				$arrTmp[] = ($intN4 % 2 == 0)?31:30;

				$WinTerms = "Number in (".join(",", $arrTmp).")";
				break;

			case 15:	//大小
				$arrTmp = array();
				$arrTmp[] = ($intN1 < 5)?1:0;
				$arrTmp[] = ($intN2 < 5)?11:10;
				$arrTmp[] = ($intN3 < 5)?21:20;
				$arrTmp[] = ($intN4 < 5)?31:30;

				$WinTerms = "Number in (".join(",", $arrTmp).")";
				break;

			case 16:	//合數單雙
				$arrTmp = array();
				$arrTmp[] = (($intN1 + $intN2) % 2 == 0)?1:0;
				$arrTmp[] = (($intN1 + $intN3) % 2 == 0)?11:10;
				$arrTmp[] = (($intN1 + $intN4) % 2 == 0)?21:20;
				$arrTmp[] = (($intN2 + $intN3) % 2 == 0)?31:30;
				$arrTmp[] = (($intN2 + $intN4) % 2 == 0)?41:40;
				$arrTmp[] = (($intN3 + $intN4) % 2 == 0)?51:50;

				$WinTerms = "Number in (".join(",", $arrTmp).")";
				break;

			case 17:	//合數大小
				$arrTmp = array();
				$arrTmp[] = (($intN1 + $intN2) < 10)?1:0;
				$arrTmp[] = (($intN1 + $intN3) < 10)?11:10;
				$arrTmp[] = (($intN1 + $intN4) < 10)?21:20;
				$arrTmp[] = (($intN2 + $intN3) < 10)?31:30;
				$arrTmp[] = (($intN2 + $intN4) < 10)?41:40;
				$arrTmp[] = (($intN3 + $intN4) < 10)?51:50;

				$WinTerms = "Number in (".join(",", $arrTmp).")";
				break;

			case 18:	//定位 - 千
				$WinTerms = "Number = ".$intN1;
				break;

			case 19:	//定位 - 百
				$WinTerms = "Number = ".$intN2;
				break;

			case 20:	//定位 - 十
				$WinTerms = "Number = ".$intN3;
				break;

			case 21:	//定位 - 個
				$WinTerms = "Number = ".$intN4;
				break;

			case 22:	//一字
				$WinTerms = "Number in (".$intN1.", ".$intN2.", ".$intN3.", ".$intN4.")";
				break;
		}  // switch($i)
		//print $intBT." => ".$WinTerms."\n";
		$arrC["WinTerms"] = $WinTerms;
		$arrC["DrawTerms"] = $DrawTerms;
		$arrC["flWinRate"] = $flWinRate;
		return $arrC;
	}


/**
 * 計算 快樂 10分 注單結果
 * @param	arrLID：樂透參數陣列
 * @param	intGID：操盤序號
 * @return	true -> 成功，false -> 失敗
 */
	function Calculate10MinWager($arrLotto, $intGID, $objScore){
		global $_ConnMaster;

		$intDeadRateType = 1;

		$flWinRate = 1;
		for($intBT = 1; $intBT <= 35; $intBT++){
			if(($intBT >= 14 && $intBT <= 28) || ($intBT >= 30 && $intBT <= 35))continue;
			$arrC = getCalculate10MinCondition($arrLotto, $intBT, $objScore -> NumberNormal, $objScore -> NumberSpecial);

			$strSQL = "update `bet_BetList` use index (GambleID) set  ".
					"MemResult = if(".$arrC["WinTerms"].", MemPayOff*".$arrC["flWinRate"].", -1*MemStake*".$arrC["flWinRate"]."), ".
					"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."), ".
					"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."), ".
					"SubRateResult = SubResult*SubRate, ".
					"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000,".
					"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000,".
					"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000, ".
					"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*".$arrC["flWinRate"]."*1000)/1000 ".
					"where GambleID = ".$intGID." ".
					"and isPayOff >=0 ".
					"and Bet_Type = ".$intBT;
			//$T = time();
			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Calculate Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
			//print $strSQL."\n";
			//print (time() - $T)."\n"."\n";
			if($arrC["DrawTerms"] != ""){
				$strSQL = "update `bet_BetList` use index (GambleID) set MemResult = 0, SubIncome = 0,  SubResult = 0, SubRateResult = 0, ".
						"MainResult = 0, MainRateResult = 0, StockResult = 0, StockRateResult = 0, DirectorResult = 0,  DirectorRateResult = 0 ".
						"where  GambleID = ".$intGID." and isPayOff >=0 and Bet_Type = ".$intBT." and ".$arrC["DrawTerms"];
				//$T = time();
				if(!PMA_mysql_query($strSQL, $_ConnMaster)){
					$GLOBALS["errormessage"] = "Calculate Wager Error!!";
					$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
					return false;
				}
				//print $strSQL."\n";
				//print (time() - $T)."\n"."\n";
			}
		}  // for($intBT = 51; $intBT <= 92; $intBT++)
		//計算連碼，不中
		if(!getJoinNumberFor10MCalculate($arrLotto, $intGID, $objScore -> NumberSpecial, $objScore -> NumberNormal))return false;
		//計算 尾數連
		if(!getMantissaFor10MCalculate($arrLotto, $intGID, $objScore -> NumberSpecial, $objScore -> NumberNormal))return false;
		//計算過關
		if(!getParlaysNumberCalculate($arrLotto, $intGID, $objScore -> NumberSpecial, $objScore -> NumberNormal))return false;
		$strSQL = "update `bet_BetList`  use index (GambleID) ".
						"set MemResult = 0, SubIncome = 0,  SubResult = 0, SubRateResult = 0, MainResult = 0, MainRateResult = 0, StockResult = 0,  StockRateResult = 0, DirectorResult = 0,  DirectorRateResult = 0 ".
						"where  GambleID = ".$intGID." and isPayOff < 0 ";

		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		if(!makeShowScoreFile($arrLotto["ID"], "", "", ""))return false;
		return true;
	}


/**
 * 取得 快樂 10分 各下注方式計算條件
 * @param	arrLotto 樂透參數陣列
 * @param	intBT 下注種類序號
 * @param	strNum 號碼字串
 * @param	strSpNum 特別號碼字串
 * @return	 Array
 */
	function getCalculate10MinCondition($arrLotto, $intBT, $strNum, $intSpNum){
		$flWinRate = 1;

		$arrNum = explode(",", $strNum);
		$intNumSum = intval($arrNum[0]) + intval($arrNum[1]) + intval($arrNum[2]) + intval($arrNum[3]);
		$intN1 = (int)$arrNum[0];	//平碼一
		$intN2 = (int)$arrNum[1];	//平碼二
		$intN3 = (int)$arrNum[2];	//平碼三
		$intN4 = (int)$arrNum[3];	//平碼四
		switch($intBT){
			case 1:	//特別號
				$WinTerms = "Number = ".$intSpNum;
				break;

			case 5:	//平碼一
				$WinTerms = "Number = ".$intN1;
				break;

			case 6:	//平碼二
				$WinTerms = "Number = ".$intN2;
				break;

			case 7:	//平碼三
				$WinTerms = "Number = ".$intN3;
				break;

			case 8:	//平碼四
				$WinTerms = "Number = ".$intN4;
				break;


			case 2:	 //特別號單雙
				if($intSpNum == (int)$arrLotto["DrawSpecial"]){
					$flWinRate = 0;
					$WinTerms = "Number = 0";
				}elseif($intSpNum % 2 == 0){
					$WinTerms = "Number = 1";
				}else{
					$WinTerms = "Number = 0";
				}
				break;

			case 3:	 //特別號大小
				if($intSpNum == (int)$arrLotto["DrawSpecial"]){
					$flWinRate = 0;
					$WinTerms = "Number = 0";
				}elseif($intSpNum >= (int)$arrLotto["SpecialOverNumber"]){
					$WinTerms = "Number = 0";
				}else{
					$WinTerms = "Number = 1";
				}
				break;

			//特碼合數單雙
			case 4:
				$intTmp = ($intSpNum % 10) + floor($intSpNum / 10);
				if($intSpNum == (int)$arrLotto["DrawSpecial"]){
					$flWinRate = 0;
					$WinTerms = "Number = 0";
				}elseif($intTmp % 2 == 0){
					$WinTerms = "Number = 1";
				}else{
					$WinTerms = "Number = 0";
				}
				break;

			//總和單雙
			case 9:
				$intNumSum += $intSpNum;
				if($intNumSum % 2 == 0){	 //雙
					$WinTerms = "Number = 1";
				}else{	//單
					$WinTerms = "Number = 0";
				}
				break;
			//總和大小
			case 10:
				$intNumSum += $intSpNum;
				if($intNumSum == (int)$arrLotto["NormalOverNumber"]){
					$flWinRate = 0;
					$WinTerms = "Number = 0";
				}elseif($intNumSum > (int)$arrLotto["NormalOverNumber"]){	 //大
					$WinTerms = "Number = 0";
				}else{	//小
					$WinTerms = "Number = 1";
				}
				break;


			//平碼 1-4 單雙
			case 11:
				$arrWin = array();
				$arrOther = array();
				foreach($arrNum as $i => $j){
					if((int)$j == (int)$arrLotto["DrawSpecial"]){	 //和局
						$arrOther[] = (string)(($i+1)*10).",".(string)(($i + 1)*10 + 1);
					}elseif((int)$j % 2 == 0){	//雙
						$arrWin[] = (string)(($i+1)*10 + 1);
					}else{	//單
						$arrWin[] = (string)(($i+1)*10);
					}
				}
				$WinTerms = "Number in (".join(",", $arrWin).")";
				if(sizeof($arrOther) > 0)$DrawTerms = "Number in (".join(",", $arrOther).")";
				break;

			//平碼 1-4 大小
			case 12:
				$arrWin = array();
				$arrOther = array();
				foreach($arrNum as $i => $j){
					if((int)$j == (int)$arrLotto["DrawSpecial"]){	 //和局
						$arrOther[] = (string)(($i+1)*10).",".(string)(($i + 1)*10 + 1);
					}elseif((int)$j >= (int)$arrLotto["SpecialOverNumber"]){	//大
						$arrWin[] = (string)(($i+1)*10);
					}else{	//小
						$arrWin[] = (string)(($i+1)*10 + 1);
					}
				}
				$WinTerms = "Number in (".join(",", $arrWin).")";
				if(sizeof($arrOther) > 0)$DrawTerms = "Number in (".join(",", $arrOther).")";
				break;

			//平碼 1-4 合數單雙
			case 13:
				$arrWin = array();
				$arrOther = array();
				foreach($arrNum as $i => $j){
					if((int)$j == (int)$arrLotto["DrawSpecial"]){	 //和局
						$arrOther[] = (string)(($i+1)*10).",".(string)(($i + 1)*10 + 1);
					}else{
						if((floor((int)$j / 10) + ((int)$j % 10)) % 2 == 0){	//合雙
							$arrWin[] = (string)(($i+1)*10 + 1);
						}else{	//合單
							$arrWin[] = (string)(($i+1)*10);
						}
					}
				}
				$WinTerms = "Number in (".join(",", $arrWin).")";
				//print $WinTerms;
				if(sizeof($arrOther) > 0)$DrawTerms = "Number in (".join(",", $arrOther).")";
				break;

			//特碼尾數
			case 29:
				$intMantissa = $intSpNum % 10;
				$WinTerms = "Number in (".$intMantissa.")";
				break;
		}  // switch($i)
		$arrC["WinTerms"] = $WinTerms;
		$arrC["DrawTerms"] = $DrawTerms;
		$arrC["flWinRate"] = $flWinRate;
		return $arrC;
	}


/**
 * 計算 快樂 10分 連碼
 * @param	arrLotto：樂透參數陣列
 * @param	intGID：操盤序號
 * @param	intNumSp：特碼號碼
 * @param	strNumN：正碼號碼字串
 * @return	 boolin
 */
	function getJoinNumberFor10MCalculate($arrLotto, $intGID, $intNumSp, $strNumN){
		global $_ConnMaster;
		$strNumSQL = "";
		$arrNumN = explode(",", $strNumN);

		//將注單輸贏金額歸零
		$strSQL = "update `bet_BetList` use index (GambleID) set `MemResult` = 0 where `GambleID` = ".$intGID." and (`Bet_Type` between 15 and 28)";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//先將中號次數歸零
		$strSQL = "update `bet_ParlaysNumberEven` set `NNWin` = 0, `NSWin` = 0 where `GambleID` = ".$intGID." and (`Bet_Type` between 15 and 28)";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//計算中號次數
		$strSQL = "update `bet_ParlaysNumberEven` set 
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball1`, ','), ',".$strNumN.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball2`, ','), ',".$strNumN.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball3`, ','), ',".$strNumN.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball4`, ','), ',".$strNumN.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball5`, ','), ',".$strNumN.",') > 0, 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball1` = ".$intNumSp.", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball2` = ".$intNumSp.", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball3` = ".$intNumSp.", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball4` = ".$intNumSp.", 1, 0) ,
			`NSWin` = `NSWin` + IF(`Ball5` = ".$intNumSp.", 1, 0) 
			where `GambleID` = ".$intGID." and (`Bet_Type` between 15 and 28)";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//統計連碼贏得金額
		$arrBTNNWin = array(15 => "(`NNWin` + `NSWin`) = 1",
											16 => "(`NNWin` + `NSWin`) = 2",
											17 => "(`NNWin` + `NSWin`) >= 2",
											18 => "(`NNWin` + `NSWin`) = 3",
											19 => "(`NNWin` + `NSWin`) >= 3",
											20 => "(`NNWin` + `NSWin`) = 4",
											21 => "(`NNWin` + `NSWin`) >= 3",
											22 => "(`NNWin` + `NSWin`) >= 4", 
											23 => "(`NNWin` + `NSWin`) = 5",
											24 => " `NNWin` = 1 and `NSWin` = 1",
			);

		foreach($arrBTNNWin as $intBT => $strNNWin){
			$strSQL = "insert into `bet_BetList`(`ID`, `MemResult`) select `BetListID`, `MemStake`*`Odds1` from `bet_ParlaysNumberEven`
			where `GambleID` = ".$intGID." and `Bet_Type` = ".$intBT." and ".$strNNWin." ON DUPLICATE KEY UPDATE `MemResult` = `MemResult` + VALUES(MemResult)";

			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";

		//統計不中贏得金額
		$strSQL = "insert into `bet_BetList`(`ID`, `MemResult`) select `BetListID`, `MemStake`*`Odds1` from `bet_ParlaysNumberEven` 
			where `GambleID` = ".$intGID." and (`Bet_Type` between 25 and 28) and `NNWin` = 0 and `NSWin` = 0 ON DUPLICATE KEY UPDATE `MemResult` = `MemResult` + VALUES(MemResult)";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";

		//計算注單輸贏金額
		$intDeadRateType = 1;
		$strSQL = "update `bet_BetList` use index (GambleID) set  ".
				"MemResult = MemResult - MemStake, ".
				"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubRateResult = SubResult*SubRate, ".
				"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*1000)/1000,".
				"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000,".
				"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000 ".
				"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
				"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000 ".
				"where `GambleID` = ".$intGID." and (`Bet_Type` between 15 and 28) ".
				"and `isPayOff` >=0 ";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";
		return true;
	}


/**
 * 計算 快樂 10 分 尾連
 * @param	arrLotto 樂透參數陣列
 * @param	intGID 操盤序號
 * @param	intNumSp 特碼號碼
 * @param	strNumN 正碼號碼字串
 * @return	boolin
 */
	function getMantissaFor10MCalculate($arrLotto, $intGID, $intNumSp, $strNumN){
		global $_ConnMaster;
		$strNumSQL = "";
		$arrNumN = explode(",", $strNumN);
		$arrMantissa[] = $intNumSp % 10;
		$arrMantissa[] = $arrNumN[0] % 10;
		$arrMantissa[] = $arrNumN[1] % 10;
		$arrMantissa[] = $arrNumN[2] % 10;
		$arrMantissa[] = $arrNumN[3] % 10;
		$strMantissa = implode(",", $arrMantissa);

		$strBT = "30,31,32,33,34,35";
		$strBTNoWin = "33,34,35";

		//將注單輸贏金額歸零
		$strSQL = "update `bet_BetList` use index (GambleID) set `MemResult` = 0 where `GambleID` = ".$intGID." and `Bet_Type` in (".$strBT.")";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Mantissa Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//先將中號次數歸零
		$strSQL = "update `bet_ParlaysNumberEven` set `NNWin` = 0, `NSWin` = 0 where `GambleID` = ".$intGID." and `Bet_Type` in (".$strBT.")";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Mantissa Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
//print $strSQL;
		//計算中號次數
		$strSQL = "update `bet_ParlaysNumberEven` set 
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball1`, ','), ',".$strMantissa.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball2`, ','), ',".$strMantissa.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball3`, ','), ',".$strMantissa.",') > 0, 1, 0) ,
			`NNWin` = `NNWin` + IF(LOCATE(CONCAT(',', `Ball4`, ','), ',".$strMantissa.",') > 0, 1, 0) 
			where `GambleID` = ".$intGID." and `Bet_Type` in (".$strBT.")";
//print $strSQL;
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Mantissa Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		//統計尾數連贏得金額
		$arrBTNNWin = array(30 => "`NNWin` = 2",
											31 => "`NNWin` = 3",
											32 => "`NNWin` = 4"
		);

		foreach($arrBTNNWin as $intBT => $strNNWin){
			$strSQL = "insert into `bet_BetList`(`ID`, `MemResult`) select `BetListID`, `MemStake`*`Odds1` from `bet_ParlaysNumberEven`
			where `GambleID` = ".$intGID." and `Bet_Type` = ".$intBT." and ".$strNNWin." ON DUPLICATE KEY UPDATE `MemResult` = `MemResult` + VALUES(MemResult)";

			if(!PMA_mysql_query($strSQL, $_ConnMaster)){
				$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
				$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
				return false;
			}
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";

		//統計不中贏得金額
		$strSQL = "insert into `bet_BetList`(`ID`, `MemResult`) select `BetListID`, `MemStake`*`Odds1` from `bet_ParlaysNumberEven` 
			where `GambleID` = ".$intGID." and `Bet_Type` in (".$strBTNoWin.") and `NNWin` = 0 and `NSWin` = 0 ON DUPLICATE KEY UPDATE `MemResult` = `MemResult` + VALUES(MemResult)";
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";

		//計算注單輸贏金額
		$intDeadRateType = 1;
		$strSQL = "update `bet_BetList` use index (GambleID) set  ".
				"MemResult = MemResult - MemStake, ".
				"SubIncome = MemResult + (MemStake*MemCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubResult = MemResult*MemExchangeRate + (MemStake*MemExchangeRate*SubCommission*if(MemResult > 0,".$intDeadRateType.",1)), ".
				"SubRateResult = SubResult*SubRate, ".
				"MainResult = SubRateResult + (MemStake*MemExchangeRate*SubRate*(MainCommission - SubCommission)*if(MemResult>0,".$intDeadRateType.",1)*1000)/1000,".
				"MainRateResult = MemResult*MemExchangeRate*MainRate + (MemStake*MemExchangeRate*MainRate*MainCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000,".
				"StockResult = MainRateResult + (MemStake*MemExchangeRate*MainRate*(StockCommission - MainCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"StockRateResult = MemResult*MemExchangeRate*StockRate + (MemStake*MemExchangeRate*StockRate*StockCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorResult = StockRateResult + (MemStake*MemExchangeRate*StockRate*(DirectorCommission - StockCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000, ".
				"DirectorRateResult = MemResult*MemExchangeRate*DirectorRate + (MemStake*MemExchangeRate*DirectorRate*DirectorCommission*if(MemResult > 0,".$intDeadRateType.",1)*1000)/1000 ".
				"Layer6Result = DirectorRateResult + (MemStake*MemExchangeRate*DirectorRate*(Layer6Commission - DirectorCommission)*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000, ".
				"Layer6RateResult = MemResult*MemExchangeRate*Layer6Rate + (MemStake*MemExchangeRate*Layer6Rate*Layer6Commission*if(MemResult > 0,".$intDeadRateType.",1)*1*1000)/1000 ".
				"where `GambleID` = ".$intGID." and `Bet_Type` in (".$strBT.") ".
				"and `isPayOff` >=0 ";
		//$T = time();
		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Join Number Calculate Wager Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nSQL:".$strSQL."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		//print $strSQL."\n";
		//print (time() - $T)."\n"."\n";
		return true;
	}
//-------------------------------------------------------//
//WagerResult_lib End
}
?>